package com.example.duanjunjie.learn.http.fetcher;

import com.example.duanjunjie.learn.http.model.Weather;
import com.example.duanjunjie.learn.http.request.WeatherRequest;
import com.example.duanjunjie.learn.http.service.ApiService;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;

/**
 * Created by duanjunjie on 2018/2/12.
 */

public class WeatherFetcher  extends RetrofitFetcher<WeatherRequest,Weather> {

    private String baseUrl="http://v.juhe.cn";
    private ApiService service;

    public WeatherFetcher() {
        OkHttpClient client=new OkHttpClient.Builder()
                .connectTimeout(3000,TimeUnit.MILLISECONDS)
                .addNetworkInterceptor(new HttpLoggingInterceptor())
                .build();

        service=creatRetrofit(baseUrl,client).create(ApiService.class);
    }

    @Override
    protected Observable<Weather> doFetch(WeatherRequest request) {
        return service.getWeather(request.cityname,request.key);
    }
}
